package com.experienceBaby.Cashbook.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;

import com.experienceBaby.Cashbook.R;
import com.experienceBaby.Cashbook.adapter.MyListviewAdapter;
import com.experienceBaby.Cashbook.databinding.FragmentAddBinding;
import com.experienceBaby.Cashbook.databinding.FragmentChartBinding;
import com.experienceBaby.Cashbook.greendao.DbController;
import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.SlidingTabLayout;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

public class ChartFragment extends Fragment {
    Spinner s;
    FragmentChartBinding binding;
    boolean aBoolean = false;
    SegmentTabLayout tabLayout_4;

    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        binding = FragmentChartBinding.inflate(inflater, container, false);

        initView();

        return binding.getRoot();
    }

    private void initView() {
        s = binding.s;
        tabLayout_4 = binding.tl4;


        ArrayList<Fragment> mFragments2 = new ArrayList<>();
        mFragments2.add(new ChartFragments(true, aBoolean));
        mFragments2.add(new ChartFragments(false, aBoolean));
        tabLayout_4.setTabData(new String[]{"月", "年"}, getActivity(), R.id.fl_change, mFragments2);
//        tabLayout_4.setTabData(new String[]{"月", "年"});

        s.setAdapter(new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_dropdown_item,
                new String[]{"支出", "收入"}));
        s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                binding.flChange.removeAllViews();

                switch (position) {
                    case 0:
                        aBoolean = false;
                        ArrayList<Fragment> mFragments2 = new ArrayList<>();
                        mFragments2.add(new ChartFragments(true, aBoolean));
                        mFragments2.add(new ChartFragments(false, aBoolean));
                        tabLayout_4.setTabData(new String[]{"月", "年"}, getActivity(), R.id.fl_change, mFragments2);
                        break;
                    case 1:
                        aBoolean = true;
                        ArrayList<Fragment> mFragments23 = new ArrayList<>();
                        mFragments23.add(new ChartFragments(true, aBoolean));
                        mFragments23.add(new ChartFragments(false, aBoolean));
                        tabLayout_4.setTabData(new String[]{"月", "年"}, getActivity(), R.id.fl_change, mFragments23);
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


    }


}
